package com.threeonemeeting.task;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;

import com.snda.lib.http.HttpUtil;
import com.snda.lib.http.ICallBack;
import com.snda.lib.task.BaseAsyncTask;
import com.threeonemeeting.DataCenter;
import com.threeonemeeting.db.AppDBHelper;
import com.threeonemeeting.list.FullMeetingInfoList;

public class LoadRecentMeetingTask extends BaseAsyncTask {

	protected int nCurrentPages = 0;

	public LoadRecentMeetingTask(Context context, ICallBack callback) {
		super(context, callback);

		this.nTaskType = HttpConst.TASKTYPE_LOADRECENTMEETING;
	}

	public void setPages(int nPages) {
		nCurrentPages = nPages;
		if (nCurrentPages < 0)
			nCurrentPages = 0;
	}

	public long getId() {
		return Math.abs(("SaveAppInfoToDBTask" + nCurrentPages).hashCode());
	}

	// 实现具体的任务
	// 实际的完成后台任务的地方
	protected Map<String, Object> doTask(Object[] params) {
		int nPage = nCurrentPages - 1;
		if (nPage < 0)
			nPage = 0;

		AppDBHelper db = DataCenter.getInstance().getDB();
		FullMeetingInfoList listMeeting = db.getPagesMeetings(10, nPage);

		Map<String, Object> mapData = new HashMap<String, Object>();
		mapData.put(HttpConst.KEY_TASK_TYPE, nTaskType);
		mapData.put(HttpUtil.KEY_ERROR_CODE, HttpUtil.ERROR_SUCCESS);
		mapData.put("page", nCurrentPages);
		mapData.put("list", listMeeting);
		return mapData;
	}
}
